package demo;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Demo3 {
    public static void main(String[] args) throws IOException {
        Scanner scanner=new Scanner(System.in);
        String rootDirPath=scanner.next();
        String content=scanner.next();
        File rootDir=new File(rootDirPath);
        if(!rootDir.isDirectory()){
            System.out.println("输入路径不合法");
            return;
        }
        List<File> list=new ArrayList<>();
        dfs(rootDir,content,list);
        for(File file:list){
            System.out.println(file.getCanonicalPath());
        }
    }
    public static void dfs(File rootDir,String content,List<File> list){
        File[] files=rootDir.listFiles();
        if(files==null){
            return;
        }
        for(File file:files){
            if(file.isFile()){
                if(isContentExists(file,content)){
                    list.add(file);
                }
            }else if(file.isDirectory()){
                dfs(file,content,list);
            }
        }
    }
    public static boolean isContentExists(File file,String content){
        StringBuilder sb=new StringBuilder();
        try(Reader reader=new FileReader(file)) {
            while (true){
                int ch=reader.read();
                if(ch==-1){
                    break;
                }
                sb.append((char)ch);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.indexOf(content)!=1;
    }
}
